﻿@{
    ViewBag.Title = "今日运维一览";
}

@using Wicresoft.UnifyShow.Business
@{
    var Announcement = ViewData["Announcement"] as List<AnnouncementModel>;
    var totalCount = (decimal)ViewData["AnnouncementCount"];
    var hasDuty = (bool)ViewData["HasTodayDuty"];

    var CommonResources = ViewData["CommonResources"] as List<CommonResourceModel>;
    var ResourceCount = (decimal)ViewData["ResourceCount"];

    var OpsResources = ViewData["OpsResources"] as List<CommonResourceModel>;
    var OpsCount = (decimal)ViewData["OpsCount"];
}

@section ScriptAndCss{
    <style type="text/css">
        .icon-overtip {
            display: inline-block;
            margin-left: 40%;
            *display: inline;
            *zoom: 1;
            height: 16px;
            width: 16px;
            background: url('/Content/images/redlight.png');
        }

        .icon-overtip-not {
            display: inline-block;
            margin-left: 40%;
            *display: inline;
            *zoom: 1;
            height: 16px;
            width: 16px;
            background: url('/Content/images/greenarrow.png');
        }

        #AnnouncementContainer li {
            padding-left: 14px;
            cursor: pointer;
            margin: 0 0 0 14px;
            padding: 3px 0;
            height: 8%;
        }

        #ResourceContainer li {
            padding-left: 14px;
            cursor: pointer;
            margin: 0 0 0 14px;
            padding: 3px 0;
            height: 8%;
        }

        #OpsContainer li {
            padding-left: 14px;
            cursor: pointer;
            margin: 0 0 0 14px;
            padding: 3px 0;
            height: 8%;
        }

        .announcementInner {
            display: inline-block;
            *display: inline;
            *zoom: 1;
            width: 80%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>

    <script type="text/javascript">
        $(function () {
            $("#ResourceList").load("@Url.Action("List", "ComResource")", function () {
                $(".document", "#ResourceList").click(function () {
                    window.open("@Url.Action("DownLoad", "ComResource")" + "?id=" + $(this).attr("data-id"));
                });
            });

            $("#DutyToday").load("@Url.Action("List", "DutyPlan")");

            var noteDisplay = function () {
                $(".note").tooltip({
                    onShow: function () {
                        $(this).tooltip('tip').css({
                            maxWidth: 300,
                            boxShadow: '1px 1px 3px #292929'
                        });
                    }
                });
            };

            var TaskRequestParam = {
                url: "/Navigate/MaintenanceTaskList",
                pageSize: 5,
                pageList: [5],
                onLoadSuccess: noteDisplay,
                onDblClickRow: function (rowIndex, rowData) {
                    showModuleDialog("/PlanManagement/TaskDetail?UserRole=2&ID=" + rowData.ID, 1080);
                    return false;
                }
            };

            $('#todayTaskList').datagrid($.extend(TaskRequestParam, { queryParams: { type: 'Today' } }));

            $('#notClosedTaskList').datagrid($.extend(TaskRequestParam, { queryParams: { type: '' } }));

            //工单查询
            var WorkOrderRequestParam = {
                url: '/Navigate/MaintenanceWorkOrderList',
                pageSize: 5,
                pageList: [5],
                onLoadSuccess: noteDisplay,
                onDblClickRow: function (rowIndex, rowData) {
                    var rnd = (new Date()).getMilliseconds() + "" + parseInt(Math.random() * 10000);
                    $.ajax({
                        url: '/Navigate/GetURL',
                        //todo:data
                        data: { type: rowData.TypeS, requestid: rowData.RequestID, nocatch: rnd },
                        success: function (result) {
                            window.open("/Account/SSO?redirectionUrl=" + encodeURI(result) + "catchid=" + rnd);
                        }

                    });
                }
            };

            $('#todayWorkorderList').datagrid($.extend(WorkOrderRequestParam, { queryParams: { type: 'Today' } }));

            $('#notClosedWorkorderList').datagrid($.extend(WorkOrderRequestParam, { queryParams: { type: '' } }));

            var AlertRequestParam = {
                url: '/Navigate/MaintenanceAlertList',
                pageSize: 5,
                pageList: [5],
                onLoadSuccess: noteDisplay
            };

            $('#todayAlertList').datagrid($.extend(AlertRequestParam, { queryParams: { type: 'Today' } }));

            $('#notClosedAlertList').datagrid($.extend(AlertRequestParam, { queryParams: { type: '' } }));

            $('table[pagination="true"]').each(function () {
                var p = $(this).datagrid('getPager');
                $(p).pagination({
                    beforePageText: '第',
                    afterPageText: '页    共 {pages} 页',
                    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'

                });
            });

        });

        var formatStatus = function (value, row, index) {
            var statusList = ["进行中", "已完成", "已取消", "已关闭"];
            return statusList[value * 1 - 1];
        };

        var formatEventStatus = function (value, row, index) {
            var statusList = ["新建", "已指派", "处理中", "暂停", "已解决", "已关闭"];
            return statusList[value * 1] || "其他";
        };

        var DateFormate = function (value, row, index) {
            if (value) {
                return value.DateStringConvert('yyyy-MM-dd');
            }
        };

        var TimeFormate = function (value, row, index) {
            if (value) {
                return value.DateStringConvert('yyyy-MM-dd hh:mm:ss');
            }
        };

        var OverFlagRender = function (value, row, index) {
            if (value == "1") {
                return '<span class="icon-overtip"></span>'
            } else {
                return '<span class="icon-overtip-not"></span>';
            }
        }

        var formateDesc = function (value, row, index) {
            var abValue = value;
            if (value.length > 10) {
                abValue = value.substring(0, 10) + "...";
            }
            var content = '<a href="#" title="' + value + '" class="note">' + abValue + '</a>';
            return content;
        }
    </script>
}
<div class="main_table">
    <div class="padding5" style="height: 32%">
        <div class="easyui-tabs" fit="true" style="width: auto; height: 100%">
            <div title="今日新增告警">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="todayAlertList">
                    <thead>
                        <tr>
                            <th field="Identify" width="150" sortable="true">设备IP</th>
                            <th field="Type" width="100" sortable="true">设备类型</th>
                            <th field="Msg" width="150" formatter="formateDesc" sortable="true">告警信息</th>
                            <th field="CreateTime" width="200" formatter="TimeFormate" sortable="true">告警时间</th>
                            <th field="LastModifiedTime" width="200" formatter="TimeFormate" sortable="true">关闭时间</th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div title="未关闭告警">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="notClosedAlertList">
                    <thead>
                        <tr>
                            <th field="Identify" width="150" sortable="true">设备IP</th>
                            <th field="Type" width="100" sortable="true">设备类型</th>
                            <th field="Msg" width="150" formatter="formateDesc" sortable="true">告警信息</th>
                            <th field="CreateTime" width="200" formatter="TimeFormate" sortable="true">告警时间</th>
                            <th field="LastModifiedTime" width="200" formatter="TimeFormate" sortable="true">关闭时间</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <div class="padding5" style="height: 32%">
        <div class="easyui-tabs" fit="true" style="width: auto; height: 100%">
            <div title="今日新增工单">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="todayWorkorderList">
                    <thead>
                        <tr>
                            <th field="RequestID" hidden="true" sortable="true" width="150"></th>
                            <th field="OrderID" sortable="true" width="150">工单ID</th>
                            <th field="TypeS" sortable="true" width="150">工单类型</th>
                            <th field="Description" sortable="true" width="140" formatter="formateDesc">摘要</th>
                            <th field="Status" sortable="true" width="70">状态</th>
                            <th field="Assigner" sortable="true" width="50">受派人</th>
                            <th field="Submitter" sortable="true" width="50">建单人</th>
                            <th field="SubmitDate" sortable="true" width="150" formatter="TimeFormate">建单时间</th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div title="未关闭工单">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="notClosedWorkorderList">
                    <thead>
                        <tr>
                            <th field="RequestID" hidden="true" sortable="true" width="150"></th>
                            <th field="OrderID" sortable="true" width="150">工单ID</th>
                            <th field="TypeS" sortable="true" width="150">工单类型</th>
                            <th field="Description" sortable="true" width="140" formatter="formateDesc">摘要</th>
                            <th field="Status" sortable="true" width="70">状态</th>
                            <th field="Assigner" sortable="true" width="50">受派人</th>
                            <th field="Submitter" sortable="true" width="50">建单人</th>
                            <th field="SubmitDate" sortable="true" width="150" formatter="TimeFormate">建单时间</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <div class="padding5" style="height: 32%">
        <div class="easyui-tabs" fit="true" style="width: auto; height: 100%">
            <div title="今日新增计划">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="todayTaskList">
                    <thead>
                        <tr>
                            <th field="ID" sortable="true" width="60">任务ID</th>
                            <th field="Status" sortable="true" formatter="formatStatus" width="60">任务状态</th>
                            <th field="TaskName" sortable="true" width="150" formatter="formateDesc">任务名称</th>
                            <th field="CreateUserName" sortable="true" width="80">创建人</th>
                            <th field="UpdateUserName" sortable="true" width="80">处理人</th>
                            <th field="CreateTime" sortable="true" formatter="DateFormate" width="90">产生时间</th>
                            <th field="CompleteTime" sortable="true" formatter="DateFormate" width="90">完成时间</th>
                            <th field="EndDate" sortable="true" formatter="DateFormate" width="90">过期时间</th>
                            <th field="OverFlag" sortable="true" formatter="OverFlagRender" width="80">是否过期</th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div title="未关闭计划">
                <table class="" fit="true" pagination="true" data-options="fit:true,singleSelect:true" id="notClosedTaskList">
                    <thead>
                        <tr>
                            <th field="ID" sortable="true" width="60">任务ID</th>
                            <th field="Status" sortable="true" formatter="formatStatus" width="60">任务状态</th>
                            <th field="TaskName" sortable="true" width="150" formatter="formateDesc">任务名称</th>
                            <th field="CreateUserName" sortable="true" width="80">创建人</th>
                            <th field="UpdateUserName" sortable="true" width="80">处理人</th>
                            <th field="CreateTime" sortable="true" formatter="DateFormate" width="90">产生时间</th>
                            <th field="CompleteTime" sortable="true" formatter="DateFormate" width="90">完成时间</th>
                            <th field="EndDate" sortable="true" formatter="DateFormate" width="90">过期时间</th>
                            <th field="OverFlag" sortable="true" formatter="OverFlagRender" width="80">是否过期</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="main_cont">
    <div class="main_cont_wrapper">
        <div class="main_cont_panel ui-icons">
            <span class="ui-icons icon-list"></span>
            <h3>电子公告</h3>
        </div>
        @*<input type="hidden" value="@(totalCount)" id="AnnouncementCount" />*@
        <div class="main_cont_menu" id="AnnouncementContainer">
            <ul class="origin" style="list-style: disc inside; height: 100%;">
                @{
                    foreach (var item in Announcement)
                    { 
                    <li onclick="openAnnouncementDetail(@item.ID);" style="list-style: disc inside;">
                        <span class="announcementInner">
                            @(item.Title)
                        </span>
                    </li>
                    }

                    if (Announcement.Count > 4)
                    {
                    <li style="text-align: right; height: 15px; font-weight: bold; position: absolute; right: 10px; bottom: 0px;">
                        <a href="/PlanManagement/AnnouncementList">>>更多...</a>
                    </li>
                    }
                }
            </ul>
        </div>
    </div>
    <div class="main_cont_wrapper">
        <div class="main_cont_panel ui-icons">
            <span class="ui-icons icon-list"></span>
            <h3 style="display: inline-block; *display: inline; *zoom: 1;"><a style="color: White" onclick="openDutyList()">值班计划</a></h3>
            @if (hasDuty)
            {
                <a style="float: right; line-height: 23px; color: white; padding-right: 10px;" onclick="openDutyDetail()">值班记录<span class="icon-edit" style="background-position: 0 0;"></span></a>
            }
        </div>
        <div class="main_cont_menu" id="DutyToday">
        </div>
    </div>

    <div class="main_cont_wrapper">
        <div class="main_cont_panel ui-icons">
            <span class="ui-icons icon-list"></span>
            <h3>运维报告</h3>
        </div>
        <input type="hidden" value="@(OpsCount)" id="OpsCount" />
        <div class="main_cont_menu" id="OpsContainer">
            <ul class="origin" style="list-style: disc inside; height: 100%;">
                @{
                    foreach (var item in OpsResources)
                    { 
                    <li style="list-style: disc inside;">
                        <span class="announcementInner">
                            <a href="@item.Url">@(item.DName)</a>
                        </span>
                    </li>
                    }

                    if (OpsResources.Count > 4)
                    {
                    <li style="text-align: right; height: 15px; font-weight: bold; position: absolute; right: 10px; bottom: 0px;">
                        <a href="/OpsReport/Search">>>更多...</a>
                    </li>
                    }
                }
            </ul>
        </div>
    </div>

    <div class="main_cont_wrapper">
        <div class="main_cont_panel ui-icons">
            <span class="ui-icons icon-list"></span>
            <h3>常用资源</h3>
        </div>
        <input type="hidden" value="@(ResourceCount)" id="ResourceCount" />
        <div class="main_cont_menu" id="ResourceContainer">
            <ul class="origin" style="list-style: disc inside; height: 100%;">
                @{
                    foreach (var item in CommonResources)
                    { 
                    <li style="list-style: disc inside;">
                        <span class="announcementInner">
                            <a href="@item.Url">@(item.DName)</a>
                        </span>
                    </li>
                    }

                    if (CommonResources.Count > 4)
                    {
                    <li style="text-align: right; height: 15px; font-weight: bold; position: absolute; right: 10px; bottom: 0px;">
                        <a href="/ComResource/Search">>>更多...</a>
                    </li>
                    }
                }
            </ul>
        </div>
    </div>



    @*    <div class="main_cont_wrapper">
        <div class="main_cont_panel ui-icons">
            <span class="ui-icons icon-list" style="cursor: pointer;" onclick="openComResourceList()"></span>
            <h3 style="display: inline-block; *display: inline; *zoom: 1;">常用资源</h3>
        </div>
        <div class="main_cont_menu" id="ResourceList">
        </div>
    </div>*@
</div>

<script type="text/javascript">

    var openDialog = function (url, width, height) {
        var _w = 1160, _h = 630;
        _w = width || _w;
        _h = height || _h;

        var iTop = 20; //获得窗口的垂直位置;
        var iLeft = (window.screen.availWidth - 10 - _w) / 2; //获得窗口的水平位置;
        window.open(url, "_blank", "width=" + _w + ",height=" + _h + ",top=" + iTop + ",left=" + iLeft + ",resizable=1,scrollbars=1,fullscreen=0");
    };

    var showModuleDialog = function (url, width, height) {
        var _w = 900, _h = 650;
        _w = width || _w;
        _h = height || _h;
        openDialog(url, _w, _h);
    }

    var openAnnouncementDetail = function (id) {
        openDialog('/PlanManagement/AnnouncementDetail?ID=' + id + '&canEdit=false', 800, 550);
    };

    var CommonResourceDownload = function (id) {
        window.open("@Url.Action("DownLoad", "ComResource")" + "?id=" + id);
    };

    var OpsResourceDownload = function (id) {
        window.open("@Url.Action("DownLoad", "OpsReport")" + "?id=" + id);
    };

    //打开排班计划列表页
    var openDutyLogList = function () {
        showModuleDialog('/DutyPlan/SeeDutyPlan');
    };

    //打开常用资搜索界面
    var openComResourceList = function () {
        showModuleDialog('/ComResource/Search')
    }

    //打开值班记录详情页面
    var openDutyDetail = function () {
        showModuleDialog('/DutyPlan/Edit?Status=ADD');
    };

    var openDutyList = function () {
        showModuleDialog('/DutyPlan/SeeDutyPlan');
    };
</script>
